package app.fugema.shop.main.center.view;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.base.common.app.LoginUtils;
import com.base.common.netBeanPackage.LiveDataWrapper;
import com.base.common.utils.DialogUtils;
import com.base.common.utils.UIUtils;
import com.base.common.view.adapter.connector.OnItemClickInterface;
import com.base.common.view.base.BaseTitleActivity;
import com.base.common.view.base.OnGetDataListener;
import com.base.common.view.widget.statelayout.StateLayout;
import com.base.common.viewmodel.BaseViewObserver;
import app.fugema.shop.databinding.ActivityRecyclerviewListBinding;

import app.fugema.shop.R;
import app.fugema.shop.main.center.adapter.HistoryGoodsAdapter;
import app.fugema.shop.main.center.model.BrowseGoodsResult;
import app.fugema.shop.main.center.vm.FootmarkVM;

/**
 * 个人中心 足迹列表
 */
public class FootMarkActivity extends BaseTitleActivity<ActivityRecyclerviewListBinding, FootmarkVM> implements OnGetDataListener
{

    private HistoryGoodsAdapter adapter;

    public static void start(Context context) {
        Intent intent = new Intent(context, FootMarkActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recyclerview_list);
    }

    @Override
    protected int getStatusBarColor()
    {
        return R.color.redColor;
    }

    @Override
    protected void initView() {

        setCloseImg(R.mipmap.ic_back_white);
        setTitle("我的足迹",R.color.white);
        adapter = new HistoryGoodsAdapter();
        adapter.setOnItemClickInterface(new OnItemClickInterface() {
            @Override
            public boolean onItemClick(View view, int onclickType, int itemType, int position, Object bean) {
                if (view.getId() == R.id.tv_time)
                {
                    //bean instanceof
                    if ( false )
                    {

                        DialogUtils.showSimpleDialog(getActivity(), false, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                UIUtils.showToastSafes("删除");
                                dialog.dismiss();
                            }
                        }, "确定删除这条记录吗？");
                    }

                    return true;
                }
                return false;
            }
        });
        binding.rvRecyclerView.setAdapter(adapter);

        viewUtils.setRefreshStateLayout(binding.rvRecyclerView, this, this);

        viewUtils.getStateLayout().setTipText(StateLayout.EMPTY, "暂无问诊历史");


    }


    @Override
    protected void initData() {

        onGetData(1);
    }


    @Override
    public void onGetData(int pn)
    {
        String userKey = LoginUtils.getToken();
        viewModel.getHistoryVisite(userKey).observe(this, new BaseViewObserver<LiveDataWrapper<BrowseGoodsResult>>(viewUtils.getStateLayout()) {
            @Override
            protected void onSuccess(LiveDataWrapper<BrowseGoodsResult> data)
            {
                viewUtils.setDataListRefreshLayout(adapter, pn, 20, data.data.getProduct());
            }

            @Override
            public boolean isEmptyData(LiveDataWrapper<BrowseGoodsResult> data)
            {
                return  UIUtils.isEmpty( data.data.getProduct());
            }

            @Override
            public boolean isRefreshLayoutData() {
                return true;
            }
        });
    }


}
